package src.lab03.test03;

import java.io.*;

/**
 * Created by 阿阿阿阿豪丶 on 2017/12/15.
 */
public class Test {
    public static void main(String[] args) {
        String path = "D:/Book.txt";
        FileOutputStream fileOutputStream = null;
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(path);
            fileOutputStream = new FileOutputStream(path);
            String input = "Beijing欢迎你";
            String input2 = "我的学号是：1606101111";
            fileOutputStream.write(input.getBytes());
            int date =1;
            while ((date =fileInputStream.read()) != -1){
                //date=fileInputStream.read();
                System.out.println(date);
            }

            RandomAccessFile randomAccessFile = new RandomAccessFile(path,"rw");
            randomAccessFile.write(input2.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
